package com.ruoyi.college.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.college.domain.Semester;
import com.ruoyi.college.service.ISemesterService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学期信息Controller
 * 
 * @author ruoyi
 * @date 2025-08-25
 */
@Controller
@RequestMapping("/college/semester")
public class SemesterController extends BaseController
{
    private String prefix = "college/semester";

    @Autowired
    private ISemesterService semesterService;

    @RequiresPermissions("college:semester:view")
    @GetMapping()
    public String semester()
    {
        return prefix + "/semester";
    }

    /**
     * 查询学期信息列表
     */
    @RequiresPermissions("college:semester:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Semester semester)
    {
        startPage();
        List<Semester> list = semesterService.selectSemesterList(semester);
        return getDataTable(list);
    }

    /**
     * 导出学期信息列表
     */
    @RequiresPermissions("college:semester:export")
    @Log(title = "学期信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Semester semester)
    {
        List<Semester> list = semesterService.selectSemesterList(semester);
        ExcelUtil<Semester> util = new ExcelUtil<Semester>(Semester.class);
        return util.exportExcel(list, "学期信息数据");
    }

    /**
     * 新增学期信息
     */
    @RequiresPermissions("college:semester:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学期信息
     */
    @RequiresPermissions("college:semester:add")
    @Log(title = "学期信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Semester semester)
    {
        return toAjax(semesterService.insertSemester(semester));
    }

    /**
     * 修改学期信息
     */
    @RequiresPermissions("college:semester:edit")
    @GetMapping("/edit/{semesterId}")
    public String edit(@PathVariable("semesterId") Long semesterId, ModelMap mmap)
    {
        Semester semester = semesterService.selectSemesterBySemesterId(semesterId);
        mmap.put("semester", semester);
        return prefix + "/edit";
    }

    /**
     * 修改保存学期信息
     */
    @RequiresPermissions("college:semester:edit")
    @Log(title = "学期信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Semester semester)
    {
        return toAjax(semesterService.updateSemester(semester));
    }

    /**
     * 删除学期信息
     */
    @RequiresPermissions("college:semester:remove")
    @Log(title = "学期信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(semesterService.deleteSemesterBySemesterIds(ids));
    }
}
